#pragma once

#include "singleton.h"
#include <string>
#include <map>
#include <vector>

#define INVALID_ID -1
static const char *defaultaction = "default";

class Entity;

struct Action
{
	std::string name;
	std::string anim;
	std::string key;
};
typedef std::vector<Action> Actions;
struct EntityDef
{
	std::string name;
	std::string type;
	std::string animname;
	int movespeed;
	int maxhp;
	Actions actions;
	Action *GetAction( std::string name );
};

typedef std::map< int, Entity *> EntityMap;
typedef std::map< std::string, EntityDef *> EntityDefMap;
class ObjManager:public CSingleton<ObjManager>
{
	IMPLEMENT_SINGLETON(ObjManager);
public:
	void UpdateObjs( int diff );
	//void RenderObjs( int x, int y, int w, int h, int offsetx, int offsety );
	void RegisterCreators( );
	Entity *CreateObj( const char *name );
	void DestroyObj( int id );
	Entity *GetEntity( int id );
	EntityDef *GetEntityDef( const char * name );
	void LoadEntityDef();
	int GenerateID( );
	
	EntityMap mObjs;
	EntityDefMap mObjDefs;
};

#define EntityCreator ObjFactory<Entity>::Instance()